// Windows/FileFind.h

#ifndef __WINDOWS_FILEFIND_H
#define __WINDOWS_FILEFIND_H


#include "Common/System/Defs.h"
#include "FileName.h"

#include "Common/MyFixes.h"

#include "FileItem.h"

namespace Common {
namespace FileSystem {
namespace Find {

class CFindFile
{
  friend class CEnumerator;
  HANDLE _handle;
public:
  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE; }
  CFindFile(): _handle(INVALID_HANDLE_VALUE) {}
  ~CFindFile() {  Close(); }
  bool FindFirst(LPCTSTR wildcard,File::CFileInfo *pfileInfo);
  bool FindNext(File::CFileInfo *pfileInfo);
  bool Close();
};

bool DoesFileExist(LPCTSTR name);
bool DoesDirExist(LPCTSTR name);
bool DoesFileOrDirExist(LPCTSTR name);

class CEnumerator
{
  CFindFile _findFile;
  CString _wildcard;
  bool NextAny(File::CFileInfo *pfileInfo);
public:
  CEnumerator(): _wildcard(FileName::kAnyStringWildcard) {}
  CEnumerator(const CString &wildcard): _wildcard(wildcard) {}
  bool Next(File::CFileInfo *pfileInfo);
  bool Next(File::CFileInfo *pfileInfo, bool &found);
};


class CFindChangeNotification
{
  HANDLE _handle;
public:
  operator HANDLE () { return _handle; }
  bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE && _handle != 0; }
  CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {}
  ~CFindChangeNotification() { Close(); }
  bool Close();
  HANDLE FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter);
  bool FindNext() { return BOOLToBool(::FindNextChangeNotification(_handle)); }
};

bool MyGetLogicalDriveStrings(CStringVector &driveStrings);
}}}
#endif

